package com.zx.controller;

import com.zx.entity.User;
import com.zx.service.UserServiceImpl;
import com.zx.util.SqlSessionFactoryUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class EnrollController {
    @RequestMapping("/register")
    public String register(String username,String password,String telephone,String name,String repassword){

        ApplicationContext ac= SqlSessionFactoryUtil.getAc();
        UserServiceImpl us=ac.getBean("userServiceImpl",UserServiceImpl.class);

        if (password==repassword){
            User user=new User(username,password,telephone,name);
            int n=us.userEnroll(user);

            if (n>0){
                return "redirect:/page/login.html";
            }else {
                return "redirect:/page/regs.html";
            }
        }else {
            return "redirect:/page/regs.html";
        }
    }


}
